package com.wx.activitys.drp.service.impl;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.wx.activitys.drp.mapper.BRoleResourceMapper;
import com.wx.activitys.drp.model.BRoleResource;

@Service("/bRoleResourceService")
public class BRoleResourceServiceImpl implements com.wx.activitys.drp.service.BRoleResourceService {

	@Autowired
	private BRoleResourceMapper bRoleResourceMapper;
	@Override
	public int addBatch(List<BRoleResource> list) {
		return bRoleResourceMapper.addBatch(list);
	}

	@Override
	public int delete(BRoleResource bRoleResource) {
		return bRoleResourceMapper.delete(bRoleResource);
	}

	@Override
	public int updateResource(int[] adId, int[] resourse) {
		BRoleResource entity = new BRoleResource();
		entity.getMap().put("ids", adId);
		int flag = bRoleResourceMapper.delete(entity);
		List<BRoleResource> list = new ArrayList<>();
		for (int i = 0; i < resourse.length; i++) {
			for (int j = 0; j < adId.length; j++) {
				BRoleResource  bRoleResource= new BRoleResource();
				bRoleResource.setAdId(adId[j]);
				bRoleResource.setResourceId(resourse[i]);
				list.add(bRoleResource);
			}
		}
		flag = bRoleResourceMapper.addBatch(list);
		return flag;
	}
}
